<template>
    <div>
        <h3>商品列表</h3>
      商品名字<input type="text" v-model="info.name" >
      商品类型<select v-model="info.levelId">
            <option value="">请选择</option>
            <option :value="item.id" v-for="item in GetMemberLevel" :key="item.id">{{item.memberLevelName}}</option>  
        </select>
        <input type="button" value="查询" class="btn btn-primary" @click="getMemberList"/>
        <table class="table table=bordered">
            <tbody>
                <tr>
                 
                    <td>商品编号</td>
                    <td>商品名称</td>
                    <td>商品</td>
                    <td>商品数量</td>
                    <td>商品类型</td>
                    <td>商品日期</td>
                    <td>商品状态</td>
                    <td>操作</td>
                </tr>
                <tr v-for="item in GetMemberList" :key='item.id'>
                    <td>{{item.code}}</td>
                    <td>{{item.name}}</td>
                    <td>{{item.sex==1}}</td>
                    <td>{{item.tel}}</td>
                    <td>{{item.memberLevelName}}</td>
                    <td>{{item.time.substr(0,10)}}</td>
                    <td>{{item.state==1?"启用":"禁用"}}</td>
                    <td>
                         <input type="button" value="解冻" class="btn btn-info" v-if="item.state==1" @click="Updatestate(item.id,0)" >
                        <input type="button" value="冻结" class="btn btn-warning" v-if="item.state==0" @click="Updatestate(item.id,1)" >
                         <input type="button" value="删除" class="btn btn-warning" v-if="item" @click="Del(item.id)" >
                          <input type="button" value="修改" class="btn btn-success" @click="Update(item.id)">
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import {ref,onMounted} from 'vue'
import axios from 'axios'
import { useRoute,useRouter } from 'vue-router'
const route=useRoute();
const router=useRouter();
let info:any=ref({
    name:'',
    levelId:'',
})

let GetMemberList:any=ref([])
let GetMemberLevel:any=ref([])
onMounted(()=>{
      getMemberList();
      getMemberLevel();
})
const Update=(id:any)=>{
    router.push({
        path:'/gai',
        query:{
            id:id,
        }
    })
        
    
}
//////////////////////////////////////////
const Del=(val:any)=>{
    axios.get('https://localhost:7000/api/Member/DelMember',{params:{id:val}}).then((res)=>{
        if(confirm('您确认删除吗？')){
            if(res.data<1){
                alert('删除成功！');
               getMemberList();
            }
        }
    })
}

/////////////////////////////////////////////
const Updatestate=(id:any,state:any)=>{
    console.log('id=',id,'state=',state)
    let f=confirm("确认要修改吗")
   if(f==true){
     axios({
         url:'https://localhost:7000/api/Member/UpdateMember',
         method:'get',
         params:{
            id:id,
            state:state
         }
    })
    .then((res)=>{
        console.log(res);
        if(res.data>0){
            alert("修改成功")
            getMemberList();
        }
        else{
            alert("修改失败")
        }
    })
    .catch((err)=>{
        console.log(err);
    })
   }
}
const getMemberLevel=()=>{
  axios({
     url:'https://localhost:7000/api/Member/MemberLevel',
    method:'get',
  })
  .then((res)=>{
    console.log(res);
    GetMemberLevel.value=res.data
  })
  .catch((err)=>{
    console.log(err);
  })
}
const getMemberList=()=>{
axios({
    url:'https://localhost:7000/api/Member/MemberList',
    method:'get',
    params:info.value,
})
.then((res)=>{
    console.log(res);
    GetMemberList.value=res.data
})
.catch((err)=>{
    console.log(err);
})
}

</script>

<style scoped>

</style>